package com.video.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.video.common.annotation.Log;
import com.video.common.core.controller.BaseController;
import com.video.common.core.domain.AjaxResult;
import com.video.common.enums.BusinessType;
import com.video.system.domain.VideoRole;
import com.video.system.service.IVideoRoleService;
import com.video.common.utils.poi.ExcelUtil;
import com.video.common.core.page.TableDataInfo;

/**
 * 角色信息Controller
 * 
 * @author lyh
 * @date 2021-07-31
 */
@RestController
@RequestMapping("/system/urole")
public class VideoRoleController extends BaseController
{
    @Autowired
    private IVideoRoleService videoRoleService;

    /**
     * 查询角色信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:urole:list')")
    @GetMapping("/list")
    public TableDataInfo list(VideoRole videoRole)
    {
        startPage();
        List<VideoRole> list = videoRoleService.selectVideoRoleList(videoRole);
        return getDataTable(list);
    }

    /**
     * 导出角色信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:urole:export')")
    @Log(title = "角色信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(VideoRole videoRole)
    {
        List<VideoRole> list = videoRoleService.selectVideoRoleList(videoRole);
        ExcelUtil<VideoRole> util = new ExcelUtil<VideoRole>(VideoRole.class);
        return util.exportExcel(list, "角色信息数据");
    }

    /**
     * 获取角色信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:urole:query')")
    @GetMapping(value = "/{roleId}")
    public AjaxResult getInfo(@PathVariable("roleId") Long roleId)
    {
        return AjaxResult.success(videoRoleService.selectVideoRoleById(roleId));
    }

    /**
     * 新增角色信息
     */
    @PreAuthorize("@ss.hasPermi('system:urole:add')")
    @Log(title = "角色信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VideoRole videoRole)
    {
        return toAjax(videoRoleService.insertVideoRole(videoRole));
    }

    /**
     * 修改角色信息
     */
    @PreAuthorize("@ss.hasPermi('system:urole:edit')")
    @Log(title = "角色信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VideoRole videoRole)
    {
        return toAjax(videoRoleService.updateVideoRole(videoRole));
    }

    /**
     * 删除角色信息
     */
    @PreAuthorize("@ss.hasPermi('system:urole:remove')")
    @Log(title = "角色信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{roleIds}")
    public AjaxResult remove(@PathVariable Long[] roleIds)
    {
        return toAjax(videoRoleService.deleteVideoRoleByIds(roleIds));
    }
}
